import React, { useContext, useReducer, createContext } from 'react'
import App from '../App'

export const Context = createContext()

const reducer = (state, action) => {
    let NewState = JSON.parse(JSON.stringify(state))
    switch(action.type) {
        case "ADD":
            NewState.count += 1
            return NewState
    }
}

const initState = {
    count: 1
}

function Store() {
    let [state, dispatch] = useReducer(reducer, initState)
    return (
        <div>
            <Context.Provider value={{
                state,
                dispatch
            }}>
                <App/>
            </Context.Provider>
        </div>
    )
}

export default Store
